package com.up.vms.domain.shared;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service("appService")
public class AppServiceImpl implements AppService {

	@Value("${appid.secret.list}")
	private String appidSecretList;

    @Override
    public App getAppByAppId(String appId) {
    	App app = new App();
    	String[] secrets = appidSecretList.split(",");
		for (String secret : secrets) {
			String[] apps = secret.split(":");
			if(apps.length < 2){
				return null;
			}
			if(appId.equals(apps[0])) {
				app.setAppId(apps[0]);
				app.setAccessSecret(apps[1]);
				return app;
			}
		}
		return null;
    }

}
